package net.mlike.openssp.server.service.impl;

import net.mlike.openssp.server.search.BaseSearch;
import net.mlike.openssp.server.service.BaseService;
import org.springframework.data.domain.Page;

import javax.transaction.Transactional;

/**
 * Created by wallellen@hotmail.com on 5/26/18.
 */
@Transactional
public abstract class BaseServiceImpl<T> implements BaseService<T> {
    @Override
    public T findById(String id) {
        return (T) getRepository().findById(id).orElse(null);
    }

    @Override
    public void save(T role) {
        getRepository().save(role);
    }

    @Override
    public void delete(String id) {
        getRepository().deleteById(id);
    }

    @Override
    public Page<T> findBySearch(BaseSearch search) {
        return getRepository().findAll(search.getCondition(), search);
    }
}
